layui.define([ 'form', 'laydate', 'table', 'element' ], function(exports) {
    var form = layui.form;
    var laydate = layui.laydate;
    var table = layui.table;
    var fsTab = layui.fsTab;
    var element = layui.element;
    var buyHouseSubsidiesTable = null;
    var view ={
        init:function(){
            this.initTable();
            this.initSearchForm();
            this.initToolBar();
            window.dataReload = function(){
                Lib.doSearchForm($("#searchForm"),buyHouseSubsidiesTable)
            }
        },
        initTable:function(){
            buyHouseSubsidiesTable = table.render({
                elem : '#buyHouseSubsidiesTable',
                height : Lib.getTableHeight(),
                cellMinWidth: 100,
                method : 'post',
                url : Common.ctxPath + '/cms/buyHouseSubsidies/list.json' // 数据接口
                ,page : Lib.tablePage // 开启分页
                ,limit : 10,
                cols : [ [ // 表头
                    {
                        type : 'checkbox',
                        fixed:'left',
                    },

                {

                    field : 'name', 
                        title : '姓名',
                    align: 'center',
                    width:"165"
                },
                {

                    field : 'year', 
                        title : '年度',
                    width:"80"
                },
                {

                    field : 'creationDate', 
                        title : '创建日期',
                    align: 'center',
                    width:"180"
                },
                {

                    field : 'businessState', 
                        title : '业务状态',
                    align: 'center',
                    width:"135"
                },
                {

                    field : 'declareYearText',
                        title : '申报补贴年次',
                    width:'120'
                },
                {

                    field : 'declareMoney', 
                        title : '补贴金额',
                    align: 'right',
                    width:"135",templet:function (d) {
                    return Common.getMoney(d.declareMoney);
                }
                },
                {

                    field : 'firstBuyHouseText',
                        title : '是否首次购房',
                    width:'120'
                }

        ] ]

        });

            table.on('checkbox(buyHouseSubsidiesTable)', function(obj){
                var buyHouseSubsidies = obj.data;
                if(obj.checked){
                    //按钮逻辑Lib.buttonEnable()
                }else{

                }
            })
        },

        initSearchForm:function(){
            Lib.initSearchForm( $("#searchForm"),buyHouseSubsidiesTable,form);
        },
        initToolBar:function(){
            toolbar = {
                add : function() { // 获取选中数据
                    Common.post("/cms/common/notLeave.json?declarationType=buy_house_subsidies", {}, function(data){
                            var url = "/cms/buyHouseSubsidies/add.do";
                            // Lib.innerAddTab(url);
                            // window.location.href = url;
                             Common.openDlg(url,"购房补贴>新增");
                    })

                },
                edit : function() { // 获取选中数目
                    var data = Common.getObtainState(table,"buyHouseSubsidiesTable");
                    if(data==null){
                        return ;
                    }
                    var url = "/cms/buyHouseSubsidies/edit.do?id="+data.id;
                    Common.openDlg(url,"购房补贴>编辑");
                },
                find : function() { // 获取选中数目
                    var data = Common.getOneFromTable(table,"buyHouseSubsidiesTable");
                    if(data==null){
                        return ;
                    }
                    var url = "/cms/buyHouseSubsidies/findenterprise.do?id="+data.id;
                    Common.openDlg(url,"购房补贴受理>查看");
                },
                del : function() {
                    layui.use(['del'], function(){
                        var delView = layui.del
                        delView.delBatch();
                    });
                },
                process : function() { // 获取选中数目
                    var businessType = Common.businessType.BUYHOUSE;
                    var data = Common.getOneFromTable(table,"buyHouseSubsidiesTable");
                    if(data==null){
                        return ;
                    }
                    var url = "/cms/businessProcess/index.do?businessType="+businessType + "&businessId="+data.id;
                    Common.openDlg(url,"流程信息>编辑");
                },
                terminal : function() { // 获取选中数目
                    var data = Common.getOneFromTable(table,"buyHouseSubsidiesTable");
                    if(data==null){
                        return ;
                    }
                    var url = "/cms/buyHouseSubsidies/terminal.do";
                    Common.post(url, {id:data.id}, function(){
                        Common.info("终止结束");
                        dataReload();
                    })
                }
        };
            $('.ext-toolbar').on('click', function() {
                var type = $(this).data('type');
                toolbar[type] ? toolbar[type].call(this) : '';
            });
        }
    }
    exports('index',view);

});